package com.cskaoyan.wordmemorize.controller.admin;

import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.DeleteBookOperateDTO;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.dto.admin.VocBookDTO;
import com.cskaoyan.wordmemorize.request.BatchDeleteCommand;
import com.cskaoyan.wordmemorize.request.VocBookCommand;
import com.cskaoyan.wordmemorize.request.VocBookPageRequest;
import com.cskaoyan.wordmemorize.service.VocBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/voc")
public class AdminVocBookController {

    @Autowired
    VocBookService vocBookService;

    // 添加书籍
    @PostMapping("/book")
    public Result<Long> addBook(@RequestBody VocBookCommand command) {
        Long id = vocBookService.addVocBook(command);
        return Result.ok(id);
    }

    // 修改书籍
    @PutMapping("/book")
    public Result<Object> updateBook(@RequestBody VocBookCommand command) {
        vocBookService.updateVocBook(command);
        return Result.ok("更新成功");
    }

    // 获取书籍列表（分页）
    @GetMapping("/book/list")
    public Result<PageDTO<VocBookDTO>> getBookList(VocBookPageRequest pageRequest) {
        PageDTO<VocBookDTO> page = vocBookService.getBookPage(pageRequest);
        return Result.ok(page);
    }

    // 批量删除书籍
    @DeleteMapping("/books")
    public Result<List<DeleteBookOperateDTO>> deleteBooks(@RequestBody BatchDeleteCommand command) {
        List<DeleteBookOperateDTO> result = vocBookService.deleteVocBooks(command);
        return Result.ok(result);
    }

    // 删除指定书籍
    @DeleteMapping("/book/{bookId}")
    public Result<DeleteBookOperateDTO> deleteBook(@PathVariable Long bookId) {
        DeleteBookOperateDTO result = vocBookService.deleteVocBook(bookId);
        return Result.ok(result);
    }
}
